<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Advertise extends Admin_Controller{
	
	public function __construct(){
		parent::__construct();
		$this->loadData('controllerName',$this->router->fetch_class());
	}
	
	public function index(){
		//$this->headTitle('Quảng cáo - Admin Panel');
		//$this->loadView('administrator/advertise/index');
		redirect('administrator/advertise/manager');
	}
	
	//Quan ly quảng cáo
	public function manager(){
		$per_page = 20;
		$num_link = 7;
		$this->load->helper('form');
		$this->load->library('form_validation');
		$this->loadScript(base_url('js/jquery.validate.js'));
		$this->loadScript(base_url('js/localization/messages_vi.js'));
		$this->loadScript(base_url('js/admin/jquery.modify.js'));
		$this->loadScript(base_url('js/admin/jquery.update.status.js'));
		$this->headTitle('Quản lý quảng cáo - Admin Panel');
		
		$currentPage = $this->input->get('page',true);
		$currentPage = (!empty($currentPage))?$currentPage:'1';
		$this->load->model('Advertise_Model');
		$countads = $this->Advertise_Model->countAds();
		$this->loadData('countads',$countads);
		$pagingConfig = $this->init_pagination('administrator/advertise/manager?act=paging', $countads, $per_page, $num_link);
		$this->loadData('paging', $this->pagination->create_links());
		$this->loadData('listads', $this->Advertise_Model->getAdsLimit((($currentPage-1) * $pagingConfig['per_page']), $pagingConfig['per_page']));
		if($this->input->post()){
			if($this->form_validation->run('formsearch') == true){
				$keysearch = trim($this->input->post('keysearch', true));
				$this->loadData('textkeysearch', $keysearch);
				$this->loadData('listads', $this->Advertise_Model->searchAds($keysearch));
			}

		}
		$this->loadView('administrator/advertise/manager');
	
	}
}